package com.game.modular.game.act.battle;

import com.game.comment.core.ResponseResult;
import com.game.comment.util.JwtUtils;

import com.game.config.netty.annotation.ActionController;
import com.game.config.netty.annotation.ActionMethod;
import com.game.modular.game.act.battle.vo.BattleVo;
import com.game.modular.game.playerMatch.service.PvpCityBuildServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@Api(tags = "pvp内政建筑")
@Validated
@RestController
@AllArgsConstructor
@ActionController(2)
@RequestMapping("/pvpCityBuildAct")
public class PvpCityBuildAction {
    @Resource
    private PvpCityBuildServiceImpl pvpCityBuildService;

    @ApiOperation("自己内政建筑")
    @ActionMethod(1)
    @PostMapping("/list")
    public ResponseResult<?> listMyCityBuilding(@RequestHeader String token) {
        Long playerId = JwtUtils.getPlayerId(token);
        return ResponseResult.success(pvpCityBuildService.map(playerId));
    }

    @ApiOperation("内政建造")
    @ActionMethod(2)
    @PostMapping("/create")
    public ResponseResult<?> build(
            @RequestHeader String token,
            @Valid @RequestBody BattleVo.PvpCityBuildVo.build param
    ) throws InterruptedException {
        Long playerId = JwtUtils.getPlayerId(token);
        return ResponseResult.success(pvpCityBuildService.build(
                playerId, param.getTargetCityId(), param.getCityBuildNo(), param.getCoreCityBuildingId(), param.getCoreCityBuildingId())
        );
    }

    @ApiOperation("内政建造升级")
    @ActionMethod(3)
    @PostMapping("/upgrade")
    public ResponseResult<?> upgrade(
            @RequestHeader String token,
            @Valid @RequestBody BattleVo.PvpCityBuildVo.upgrade param
    ) {
        Long playerId = JwtUtils.getPlayerId(token);
        return ResponseResult.success(pvpCityBuildService.buildUp(
                playerId, param.getTargetCityId(), param.getCityBuildNo())
        );
    }

    @ApiOperation("内政拆除")
    @ActionMethod(4)
    @PostMapping("/remove")
    public ResponseResult<?> remove(
            @RequestHeader String token,
            @Valid @RequestBody BattleVo.PvpCityBuildVo.remove param
    ) {
        Long playerId = JwtUtils.getPlayerId(token);
        pvpCityBuildService.remove(playerId, param.getTargetCityId(), param.getCityBuildNo());
        return ResponseResult.success("拆除成功");
    }

    @ApiOperation("使用道具")
    @ActionMethod(5)
    @PostMapping("/useProp")
    public ResponseResult<?> useProp(
            @RequestHeader String token,
            @Valid @RequestBody BattleVo.PvpCityBuildVo.usePropForCityBuilding param
    ) {
        Long playerId = JwtUtils.getPlayerId(token);
        return ResponseResult.success("使用成功", pvpCityBuildService.useCityBuildingProp(
                playerId,
                param.getTargetCityId(),
                param.getNo(),
                param.getCorePropId())
        );
    }
}